package com.briup.estore.service;

import com.briup.estore.bean.Book;
import com.briup.estore.bean.Collect;
import com.briup.estore.mapper.BookMapper;
import com.briup.estore.mapper.collectMapper;
import com.briup.estore.utils.BeanCopyUtils;
import com.briup.estore.vo.BookInfoVO;
import com.briup.estore.vo.BookVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookService {
    @Resource
    private BookMapper bookMapper;

    @Resource
    private collectMapper collectMapper;

    public List<BookVO> showBooks() {
        List<Book> books = bookMapper.selectBooksBefore20();
        List<BookVO> bookVOS = BeanCopyUtils.copyBeanList(books, BookVO.class);
        return bookVOS;
    }

    public List<BookVO> searchBooks(String query) {
        List<BookVO> book = bookMapper.searchBook(query);
        return book;
    }

    public List<BookVO> findByCategory(Integer id) {
        List<BookVO> book = bookMapper.findByCategory(id);
        return book;
    }

    public BookInfoVO selectbyID(String userId,int id) {
        BookInfoVO book = bookMapper.selectbyID(id);
        Collect collect = collectMapper.isCollect(userId,id);
        book.setCollect(collect!=null);
        return book;
    }
}
